<!-- 头部 -->
{include file="public/top" /}
<!-- /头部 -->
<div class="main-container" id="main-container">
    <!-- left -->
    {include file="public/left" /}
    <!-- /left -->
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="ace-icon fa fa-home home-icon"></i> <a href="#">首页</a>
                    </li>
                    <li><a href="#">用户管理</a></li>
                    <li class="active">编辑用户</li>
                </ul>
                <!-- /.nav-search -->
            </div>
            <div class="page-content">
                <div class="page-header">
                    <div class="row">
                        <div class="col-md-6">
                            <h1>
                                编辑用户
                                <small>
                                    <i class="ace-icon fa fa-angle-double-right"></i>
                                    编辑用户
                                </small>
                            </h1>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget-box">
                            <!--<div class="widget-header">-->
                                <!--<h5 class="widget-title" style="color: #2679b5; font-size: 16px;">新增用户组</h5>-->
                            <!--</div>-->

                            <div class="widget-body">
                                <div class="widget-main padding-16">
                                    <div class="row">
                                        <form action="{:url('user/edit')}" method="POST" id="addsubmit" onsubmit="return validate(this)">
                                            <div class="form-group clearfix">
                                                <label class="col-sm-1 label_control no-padding-right" > 用户名 </label>
                                                <div class="col-sm-10">
                                                    <input type="text" class="col-xs-10 col-sm-3" id="editusername" name="username" value="{$userinfo.username}" >
                                                </div>
                                            </div>

                                            <div class="form-group clearfix">
                                                <label class="col-sm-1 label_control no-padding-right" > 密码 </label>
                                                <div class="col-sm-10">
                                                    <input type="text" class="col-xs-10 col-sm-3"  name="password" value="" >

                                                </div>
                                            </div>
                                            <div class="form-group clearfix">
                                                <label class="col-sm-1 label_control no-padding-right" > 用户组 </label>
                                                <div class="col-sm-10 pt">
                                                    {volist name="authgroupres" id="authgroup" }
                                                    <label >
                                                        <input name="group_ids[]" type="checkbox" {if condition="is_array($userinfo.group_id)&&in_array($authgroup.id , $userinfo.group_id)"} checked {/if} class="ace" value="{$authgroup.id}">
                                                        <span class="lbl">{$authgroup.title}</span> &nbsp;&nbsp;&nbsp;
                                                    </label>
                                                    {/volist}

                                                </div>
                                            </div>
                                            <input type="hidden" name="uid" value="{$userinfo.uid}">
                                            <br>
                                            <div class="col-xs-6 align-center">
                                                <input type="submit"  value="提交保存" class="btn btn-info input-small btn-round">

                                            </div>
                                        </form>





                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<script>

    function validate (theform){
        var addusername = $('#addusername').val();
        var adduserpwd = $('#adduserpwd').val();
        if(addusername == '' ){
            Msg('用户名不能为空');
            return false;
        }
        if(adduserpwd == '' ){
            Msg('密码不能为空');
            return false;
        }
        return true;
    }
    function edit_validate (theform){
        var editusername = $('#editusername').val();
        var editpwd = $('#editpwd').val();

        if(editusername == '' ){
            Msg('用户名不能为空');
            return false;
        }
        if(editpwd == '' ){
            Msg('密码不能为空');
            return false;
        }
        return true;
    }

    $(function () {
        //动态选择框，上下级选中状态变化
        $('input.checkbox-parent').on('change', function () {
            var dataid = $(this).attr("dataid");
            $('input[dataid^=' + dataid + ']').prop('checked', $(this).is(':checked'));
        });
        $('input.checkbox-child').on('change', function () {
            var dataid = $(this).attr("dataid");
            dataid = dataid.substring(0, dataid.lastIndexOf("-"));
            var parent = $('input[dataid=' + dataid + ']');
            if ($(this).is(':checked')) {
                parent.prop('checked', true);
                //循环到顶级
                while (dataid.lastIndexOf("-") != 2) {
                    dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                    parent = $('input[dataid=' + dataid + ']');
                    parent.prop('checked', true);
                }
            } else {
                //父级
                if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                    parent.prop('checked', false);
                    //循环到顶级
                    while (dataid.lastIndexOf("-") != 2) {
                        dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                        parent = $('input[dataid=' + dataid + ']');
                        if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                            parent.prop('checked', false);
                        }
                    }
                }
            }
        });
    });


</script>